package com.socket.nio.demos;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @auther zhangwj
 * @date 2020/6/17 1:42 下午
 */
public class FileChannelDemo {

    public static void main(String[] args) throws IOException {
        File file = new File("/Users/zhangwj/Downloads/text.txt");
        FileInputStream fileInputStream = new FileInputStream(file);
        FileChannel fileChannel = fileInputStream.getChannel();
        ByteBuffer byteBuffer = ByteBuffer.allocate(1024);
        while (fileChannel.read(byteBuffer) != -1) {
            System.out.println(new String(byteBuffer.array()));
        }
        fileChannel.close();
    }
}
